#include "jouercarte.h"
#include "ui_jouercarte.h"
#include "QSFMLScreen.h"
#include "mainwindow.h"

Jouercarte::Jouercarte(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Jouercarte),
    m_gameScreen((QSFMLScreen*)0)
{
    dial = new dialog(this);
    ui->setupUi(this);
    resize(800,616);
    ui->centralwidget->setContentsMargins(0,0,0,0);
    ui->frame->setContentsMargins(0,0,0,0);
    ui->verticalLayout->setContentsMargins(0,0,0,0);
}

Jouercarte::~Jouercarte()
{
    delete ui;
    delete dial;
    delete m_gameScreen;
}

void Jouercarte::on_actionRetour_au_menu_principal_activated()
{

    MainWindow *fen_princ = new MainWindow;
    fen_princ->show();
    this->close();
    //delete this;
}

void Jouercarte::on_actionNouvelle_partie_activated()
{
    dial->ouvrirDialogue(1);
    if (dial->getfichier() != NULL)
    {
        const quint16 windowWidth = 800; //25 (mapDefaultWidth)  x 32 (tileWidth)
        const quint16 windowHeight = 576;//18 (mapDefaultHeight) x 32 (tileHeight)

        //Integrates a SFMLView in the main window
        QSFMLScreen* formerGameScreen = m_gameScreen;
        m_gameScreen = new QSFMLScreen(ui->frame, QPoint(0, 0), QSize(windowWidth, windowHeight),dial->getfichier(),0);
        delete formerGameScreen;
        m_gameScreen->show();
    }
}

void Jouercarte::on_actionCharger_une_partie_activated()
{
    dial->ouvrirDialogue(2);
    if (dial->getfichier() != NULL)
    {
        const quint16 windowWidth = 800; //25 (mapDefaultWidth)  x 32 (tileWidth)
        const quint16 windowHeight = 576;//18 (mapDefaultHeight) x 32 (tileHeight)

        //Integrates a SFMLView in the main window
        QSFMLScreen* formerGameScreen = m_gameScreen;
        m_gameScreen = new QSFMLScreen(ui->frame, QPoint(0, 0), QSize(windowWidth, windowHeight),dial->getfichier(),1);
        delete formerGameScreen;
        m_gameScreen->show();
    }
}

void Jouercarte::on_actionSauvegarder_activated()
{

    m_gameScreen->getGameMap()->save();
}
